package Controller.GestionGroupe;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Controller.BDD.GestionGroupeBDD;
import Model.Droit;
import Model.Groupe;
import Model.Utilisateur;

/**
 * Servlet implementation class GestionDroit
 */
@WebServlet("/GestionGroupes")
public class GestionGroupes extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GestionGroupes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
			String urlVue = "GestionGroupes.jsp";
		
			ArrayList<Groupe> groupes =  new ArrayList<Groupe>();
			
			String method 		   = (String) request.getParameter("method");
			String name			   = (String) request.getParameter("value");
			
			if(method != null && method.equals("ajax")){
				urlVue = "GestionGroupe/ajaxGroupes.jsp";
				groupes = GestionGroupeBDD.recupererListeGroupeByName(name);
				
	
			} else {
				groupes = GestionGroupeBDD.recupererListeGroupe();
			}

		
			request.setAttribute("Groupes", groupes);
			request.getRequestDispatcher(urlVue).forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
